package com.itboye.ihomebank.activity.home;

import android.annotation.SuppressLint;
import android.content.Intent;
import android.graphics.Color;
import android.graphics.drawable.BitmapDrawable;
import android.os.Bundle;
import android.text.InputFilter;
import android.util.Log;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup.MarginLayoutParams;
import android.view.WindowManager;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.PopupWindow;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.ToggleButton;

import com.android.volley.Response;
import com.android.volley.VolleyError;
import com.bigkoo.pickerview.OptionsPickerView;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import com.itboye.ihomebank.R;
import com.itboye.ihomebank.base.BaseOtherActivity;
import com.itboye.ihomebank.base.MyApplcation;
import com.itboye.ihomebank.bean.AvatarBeans;
import com.itboye.ihomebank.bean.AvatarDataBeans;
import com.itboye.ihomebank.bean.EditBean;
import com.itboye.ihomebank.bean.FaBuHouseBean;
import com.itboye.ihomebank.bean.HouseZiDianBean;
import com.itboye.ihomebank.bean.HouseZiDianBean.houseDecoration;
import com.itboye.ihomebank.bean.HouseZiDianBean.houseDevice;
import com.itboye.ihomebank.bean.HouseZiDianBean.houseFeature;
import com.itboye.ihomebank.bean.HouseZiDianBean.houseOrientation;
import com.itboye.ihomebank.bean.HouseZiDianBean.housePay;
import com.itboye.ihomebank.bean.ResultEntity;
import com.itboye.ihomebank.constants.NetPublicConstant;
import com.itboye.ihomebank.constants.SPContants;
import com.itboye.ihomebank.custom.FlowLayout;
import com.itboye.ihomebank.presenter.HousePresenter;
import com.itboye.ihomebank.presenter.UserPresenter;
import com.itboye.ihomebank.util.ByAlert;
import com.itboye.ihomebank.util.CashierInputFilter;
import com.itboye.ihomebank.util.MyGongJv;
import com.itboye.ihomebank.util.SPUtils;
import com.itboye.ihomebank.util.UploadImage;
import com.itboye.ihomebank.util.WriteYongJinWindow;
import com.itboye.ihomebank.util.uploadmultipleimage.MultipartRequest;

import org.json.JSONException;
import org.json.JSONObject;

import java.io.File;
import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Observable;
import java.util.Observer;

/**
 * 发布房源（2）
 */
public class ActivityFaBuHouseTwo extends BaseOtherActivity implements
        Observer,
        UploadImage.OnUploadlistener {
    View v_statusbar;
    private ImageView close_icon;// 返回图片
    private TextView add_shap_title_tv;// 标题

    private TextView fabu_house_ok;
    RelativeLayout fabu_two_zujin, fabu_two_dingjin, fabu_two_yongjin,
            fabu_two_mianji, fabu_two_huxing, fabu_two_zulin, fabu_two_louceng,
            fabu_two_chaoxiang, fabu_two_zong, fabu_two_chengdu,
            fabu_two_fangshi, fabu_two_miaoshu;
    // 户型
    private TextView fabu_huxing;
    ToggleButton fabu_yongjin;
    // 租金，佣金，面积，楼层，总楼层，描述
    TextView fabu_mianji,fabu_louceng,fabu_zong;
    private EditText fabu_zujin,fabu_miaoshu;
    /**
     * 装修程度，支付方式，朝向，租赁房间
     */
    TextView fabu_chengdu, fabu_fangshi, fabu_chaoxiang, fabu_woshi;
    /**
     * 详细地址
     */
    String addressdetail;
    /**
     * 装修程度的id，支付方式的id，朝向的id
     */
    private String chengdu="", fangshi="", chaoxiang="";

    // 房源特色，室内配置
    FlowLayout fabu_flowLayout01, fabu_flowLayout02;
    // 房源特色
    private StringBuffer biao01 = new StringBuffer();
    // 室内配置
    private StringBuffer biao02 = new StringBuffer();

    Intent intent;
    String xiaoquCode, phone, people, title;
    private UserPresenter userPresenter;

    private HousePresenter housePresenter;// 用来获取房源字典

    private List<houseDecoration> house_decoration = new ArrayList<houseDecoration>();// 装修程度
    private List<housePay> house_pay = new ArrayList<housePay>();// 支付方式
    private List<houseFeature> house_feature = new ArrayList<HouseZiDianBean.houseFeature>();// 房源特色标签
    private List<houseDevice> house_device = new ArrayList<houseDevice>();// 室内配置
    private List<houseOrientation> house_orientation = new ArrayList<houseOrientation>();// 朝向


    /**
     * 存图片的ID
     */
    private StringBuffer sb;

    List<String> data;
    /**
     * 出租方式 : 【1=>整租,2=>合租-主卧,3=>合租-次卧】
     */
    private int type=1;
    /**
     * 户型，【1,0,0】 几室,几厅,几卫
     */
    private String huxing="";
    ArrayList<TextView> arrayListTeSe = new ArrayList<>();
    ArrayList<TextView> arrayListPeiZhi = new ArrayList<>();
    private StringBuffer stringTeSe = new StringBuffer();
    private StringBuffer stringPeiZhi = new StringBuffer();
    String detail;
    private String house_no = "";
    EditText edit_money;
    protected String yongjin= "";//佣金
    TextView yongjinwrite;
    EditBean editBean;

    List<String> alist;//图片
    List<String> alist02=new ArrayList<>();//上个页面传过来的还没上传的图片
    protected StringBuffer imgBuffer;//上传成功的图片id
    protected StringBuffer imgBuffer02;//上个页面的成功的图片id

    private OptionsPickerView pvOptionsZhiFu, pvNoLinkOptions, pvOptionsChuZu, pvOptionsChaoXiang, pvOptionsChengDu;//支付方式，户型,出租方式,房源朝向,装修程度
    private OptionsPickerView pvOptionsMianJi,pvOptionsLouCeng,pvOptionsZong;//面积,楼层，总楼层
    private ArrayList<String> options1ItemsZhiFu = new ArrayList<>();//支付方式
    private ArrayList<String> options1ItemsChaoXiang = new ArrayList<>();//房源朝向
    private ArrayList<String> options1ItemsChengDu = new ArrayList<>();//装修程度

    private OnClickListener yongjinTianXieClickListener = new OnClickListener() {

        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
            switch (v.getId()) {
                case R.id.yes:
                    if (edit_money.getText().toString().equals("")) {
                        ByAlert.alert("请先写佣金");
                    } else {
                        yongjin = edit_money.getText().toString();
                        yongjinwrite.setText(yongjin + "元");
                        jinWindow.dismiss();
                    }

                    break;
                case R.id.cancel:
                    fabu_yongjin.setChecked(false);
                    isWeiTuo = !isWeiTuo;
                    jinWindow.dismiss();
                    break;
                default:
                    break;
            }
        }
    };
    private WriteYongJinWindow jinWindow;
    private boolean isWeiTuo=false;

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.close_icon:
                finish();
                break;
            case R.id.fabu_fangshi:// 支付方式
            case R.id.fabu_two_fangshi:// 支付方式
                pvOptionsZhiFu.show();
                MyGongJv.yincang(v);
                break;
            case R.id.fabu_huxing:// 户型
            case R.id.fabu_two_huxing:// 户型
                pvNoLinkOptions.show();
                MyGongJv.yincang(v);
                break;
            case R.id.fabu_woshi:// 出租方式
            case R.id.fabu_two_zulin:// 出租方式
                pvOptionsChuZu.show();
                MyGongJv.yincang(v);
                break;
            case R.id.fabu_chaoxiang:// 楼层朝向
            case R.id.fabu_two_chaoxiang:// 楼层朝向
                pvOptionsChaoXiang.show();
                MyGongJv.yincang(v);
                break;
            case R.id.fabu_chengdu:// 装修程度
            case R.id.fabu_two_chengdu:// 装修程度
                pvOptionsChengDu.show();
                MyGongJv.yincang(v);
                break;
            case R.id.fabu_mianji:// 建筑面积
            case R.id.fabu_two_mianji:// 建筑面积
                pvOptionsMianJi.show();
                MyGongJv.yincang(v);
                break;
            case R.id.fabu_louceng:// 楼层
            case R.id.fabu_two_louceng:// 楼层
                pvOptionsLouCeng.show();
                MyGongJv.yincang(v);
                break;
            case R.id.fabu_zong:// 总楼层
            case R.id.fabu_two_zong:// 总楼层
                pvOptionsZong.show();
                MyGongJv.yincang(v);
                break;
            case R.id.fabu_yongjin:
                isWeiTuo = !isWeiTuo;
                if (isWeiTuo) {
                    jinWindow = new WriteYongJinWindow(this,
                            yongjinTianXieClickListener);
                    edit_money = (EditText) jinWindow.getContentView()
                            .findViewById(R.id.edit_money);
                    jinWindow.setBackgroundDrawable(new BitmapDrawable());
                    jinWindow.setFocusable(true);
                    jinWindow.setSoftInputMode(PopupWindow.INPUT_METHOD_NEEDED);
                    jinWindow.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);
                    jinWindow.showAtLocation(v, Gravity.BOTTOM, 0, 0);
                } else {
                    yongjin = "0";
                    yongjinwrite.setText("");
                }
                break;
            case R.id.fabu_house_ok:// 完成
                String uid = (String) SPUtils.get(this, null, SPContants.USER_ID,
                        "");
                String zujin = fabu_zujin.getText().toString();
                String mianji = fabu_mianji.getText().toString();
                String louceng = fabu_louceng.getText().toString();
                String zonglouceng = fabu_zong.getText().toString();
                String miaoshu = fabu_miaoshu.getText().toString();
                String str = getIntent().getStringExtra("imgIds");

                addressdetail = getIntent().getStringExtra("address");
                if (str.toString().length() > 0) {
                    str = str.toString().substring(0, str.length() - 1);
                }
                if (zujin.equals("")) {
                    ByAlert.alert("请填写租金");
                    return;
                }
                if (type == 0) {
                    ByAlert.alert("请选择出租方式");
                    return;
                }
                if (mianji.equals("")) {
                    ByAlert.alert("请选择面积");
                    return;
                }
                if (louceng.equals("")) {
                    ByAlert.alert("请填写楼层");
                    return;
                }
                if (zonglouceng.equals("")) {
                    ByAlert.alert("请选择总楼层");
                    return;
                }
                if (chaoxiang .equals("")) {
                    ByAlert.alert("请选择朝向");
                    return;
                }
                if (chengdu .equals("")) {
                    ByAlert.alert("请选择装修程度");
                    return;
                }
                if (fangshi .equals("")) {
                    ByAlert.alert("请选择支付方式");
                    return;
                }
                if (huxing .equals("")) {
                    ByAlert.alert("请选择户型");
                    return;
                }
                if (isWeiTuo) {
                    if (yongjin .equals("")) {
                        ByAlert.alert("请填写佣金");
                        return;
                    }
                }

                stringTeSe = new StringBuffer();
                for (int i = 0; i < arrayListTeSe.size(); i++) {
                    if (arrayListTeSe.get(i).getTag(R.id.tagNames).toString()
                            .equals("select")) {
                        stringTeSe.append(arrayListTeSe.get(i).getTag(R.id.tag)
                                .toString()
                                + ",");
                    }
                }
                stringPeiZhi = new StringBuffer();
                for (int i = 0; i < arrayListPeiZhi.size(); i++) {
                    if (arrayListPeiZhi.get(i).getTag(R.id.tagNames).toString()
                            .equals("select")) {
                        stringPeiZhi.append(arrayListPeiZhi.get(i).getTag(R.id.tag)
                                .toString()
                                + ",");
                    }
                }
                showProgressDialog("正在发布中,请稍后", false);

                userPresenter.getHouseAdd(
                        uid,
                        editBean == null? imgBuffer.toString():imgBuffer02+ imgBuffer.toString(),
                        xiaoquCode,
                        type,
                        people,
                        phone,
                        zujin == null ? "0" : ((int)Double.parseDouble(zujin) * 100) + "",
                        mianji,
                        huxing,
                        louceng,
                        zonglouceng,
                        chengdu,
                        fangshi,
                        chaoxiang,
                        addressdetail,
                        yongjin .equals("") ? "0" : ((int)Double.parseDouble(yongjin) * 100) + "",
                        stringTeSe.toString().length() > 0 ? stringTeSe.substring(
                                0, stringTeSe.length() - 1) : "",
                        stringPeiZhi.toString().length() > 0 ? stringPeiZhi
                                .substring(0, stringPeiZhi.length() - 1) : "", "",
                        house_no == null ? "" : house_no, "", miaoshu, title);
                fabu_house_ok.setFocusable(false);
                break;

            default:
                break;
        }

    }

    @Override
    protected int layout_id() {
        return R.layout.activity_fabu_house_two;
    }

    @Override
    protected void onInit() {
        setStatusBarHeight(v_statusbar);
        imgBuffer02=new StringBuffer();
        initOptionPicker();//支付方式
        getNoLinkData();//户型数据
        initNoLinkOptionsPicker();//户型
        getNoLinkDataFangShi();//出租方式数据
        getNoLinkDataMianJi();//面积数据
        getNoLinkDataLouCeng();//楼层数据
        getNoLinkDataLouCengZong();//总楼层数据

        linkageFangShi();// 出租方式
        linkageChaoXiang();// 房源朝向
        linkageChengDu();// 装修程度
        linkageMianJi();//房源面积
        linkageLouCeng();//楼层
        linkageLouCengZong();//总楼层
        editBean = (EditBean) getIntent().getSerializableExtra("model");// 是否是修改房源，editbean为空即发布房源，不为空即为修改房源
        if (editBean != null) {
            List<String>  alists = (List<String>) getIntent().getSerializableExtra("list");
            for (int i = 0; i < alists.size(); i++) {//当时新添加的图片的话   上传   如果是之前的图片，则保存下来
                if (alists.get(i).toString().contains("/")){
                    alist02.add(alists.get(i).toString());
                }else{
                    if (!alists.get(i).toString().equals("0")){
                        imgBuffer02.append(alists.get(i).toString()+",");
                    }
                }
            }
            fabu_zujin
                    .setText((Double.parseDouble(editBean.getRent() + "") / 100 + ""));
            fabu_fangshi.setText(editBean.getPayTypes().get(0).getName());
            fangshi = editBean.getPayTypes().get(0).getId() + "";
            fabu_mianji.setText(editBean.getHouseArea() + "");
            fabu_huxing.setText(editBean.getHouseRoom() + "室"
                    + editBean.getHouseHall() + "厅" + editBean.getToilet()
                    + "卫");
            fabu_woshi.setText(editBean.getRentTypeName() + "");
            type = Integer.parseInt(editBean.getRentType());

            if (type==1){
                fabu_woshi.setText("整租");
            }else if (type==2){
                fabu_woshi.setText("合租-主卧");
            }else if (type==3){
                fabu_woshi.setText("合租-次卧");
            }else if (type==4){
                fabu_woshi.setText("日租");
            }
            fabu_louceng.setText(editBean.getFloorAt() + "");

            fabu_zong.setText(editBean.getFloorAll() + "");
            fabu_chaoxiang.setText(editBean.getHouseDirName());
            fabu_chengdu.setText(editBean.getHouseDecorationName());
            sb=new StringBuffer();
            for (int i = 0; i < editBean.getShowImgs().size(); i++) {
                sb.append(editBean.getShowImgs().get(i)+",");
            }

            chengdu=editBean.getHouseDecoration();
            chaoxiang=editBean.getHouseDir();
            huxing=editBean.getHouseRoom() + ","
                    + editBean.getHouseHall() + "," + editBean.getToilet()
                    + "";

            // fabu_flowLayout02//室内配置
            fabu_miaoshu.setText(editBean.get_abstract());
            if (Integer.parseInt(editBean.getEntrustMoney()) <= 0) {
                isWeiTuo = false;
                yongjinwrite.setText("");
                fabu_yongjin.setChecked(false);
            } else {
                isWeiTuo = true;
                yongjinwrite.setText(Double.parseDouble(editBean
                        .getEntrustMoney() + "")
                        / 100 + "元");
                fabu_yongjin.setChecked(true);
            }
        } else {

        }
        add_shap_title_tv.setText("发布房源");
        intent = this.getIntent();
        userPresenter = new UserPresenter(this);
        xiaoquCode = intent.getStringExtra("xiaoquCode");
        house_no = intent.getStringExtra("house_no");
        phone = intent.getStringExtra("phone");
        people = intent.getStringExtra("people");
        title = intent.getStringExtra("title");

        imgBuffer = new StringBuffer();

        alist = (List<String>) getIntent().getSerializableExtra("list");
        // ByAlert.alert(alist.toString());
        String uid = SPUtils.get(this, null, SPContants.USER_ID, "") + "";
        Map<String, String> params = new HashMap<String, String>();
        params.put("uid", uid);
        params.put("type", "house");

        List<File> files = new ArrayList<>();
        if (alist != null) {
            for (int i = 0; i < alist.size(); i++) {
                files.add(new File(alist.get(i)));
            }
        }
        List<File> files02 = new ArrayList<>();
        if (alist02 != null) {
            for (int i = 0; i < alist02.size(); i++) {
                files02.add(new File(alist02.get(i)));
            }
        }
        MultipartRequest multipartRequest = new MultipartRequest(
                NetPublicConstant.URL
                        + "/file/upload?client_id=by565fa4facdb191",

                new Response.Listener<String>() {
                    @Override
                    public void onResponse(String arg0) {
                        String code = "";
                        String result = "";
                        try {
                            JSONObject jsonObject = new JSONObject(arg0);
                            code = jsonObject.getString("code");
                            result = jsonObject.getString("data");
                            if (code.equals("-1")) {
                                ByAlert.alert(result);
                            } else {
                                Gson gson = new Gson();
                                Type type = new TypeToken<AvatarBeans>() {
                                }.getType();
                                Log.v("msg", result + "我是争取的");
                                AvatarBeans avatarBeans = gson.fromJson(
                                        arg0, type);
                                for (AvatarDataBeans bean : avatarBeans
                                        .getData()) {
                                    imgBuffer.append(bean.getId() + ",");
                                }
                            }
                        } catch (JSONException e) {
                            e.printStackTrace();
                        } catch (Exception e) {
                            e.printStackTrace();
                        }
                    }
                }, new Response.ErrorListener() {

            @Override
            public void onErrorResponse(VolleyError arg0) {
                // TODO Auto-generated method stub
                ByAlert.alert(arg0);
            }
        }, "image[]", editBean == null? files:files02, params);
        MyApplcation.addRequest(multipartRequest);

        detail = intent.getStringExtra("detail");
        housePresenter = new HousePresenter(this);
        housePresenter.houseZiDian("");

        InputFilter[] filter = {new CashierInputFilter()};
        fabu_zujin.setFilters(filter);// 设置输入位金额
        // fabu_yongjin.setFilters(filter);// 设置输入位金额

    }

    @Override
    protected void onInitController() {

    }

    @Override
    protected void onReadIntent(Bundle bundle) {
        // TODO Auto-generated method stub

    }

    @Override
    public void update(Observable observable, Object data) {
        try {
            closeProgressDialog();
        } catch (Exception e) {
            // TODO: handle exception
        }
        ResultEntity entity = handlerError(data);
        // ByAlert.alert(entity.getData());
        if (entity != null) {
            if (!entity.getCode().equals(0)) {
                if (entity.getEventType() == UserPresenter.user_success) {
                    FaBuHouseBean bean = (FaBuHouseBean) entity.getData();
                } else if (entity.getEventType() == UserPresenter.user_fail) {

                }
                // 房源字典
                if (entity.getEventType() == HousePresenter.houseZiDian_success) {

                    HouseZiDianBean houseZiDianBean = (HouseZiDianBean) entity
                            .getData();

                    if (houseZiDianBean != null) {
                        house_pay.addAll(houseZiDianBean.getHouse_pay());
                        for (int i = 0; i < house_pay.size(); i++) {
                            options1ItemsZhiFu.add(house_pay.get(i).getName());
                        }
                        initOptionPicker();//支付方式
                        house_orientation.addAll(houseZiDianBean
                                .getHouse_orientation());
                        for (int i = 0; i < house_orientation.size(); i++) {
                            options1ItemsChaoXiang.add(house_orientation.get(i).getName());
                        }
                        house_decoration.addAll(houseZiDianBean
                                .getHouse_decoration());
                        for (int i = 0; i < house_decoration.size(); i++) {
                            options1ItemsChengDu.add(house_decoration.get(i).getName());
                        }
                        house_feature
                                .addAll(houseZiDianBean.getHouse_feature());
                        house_device.addAll(houseZiDianBean.getHouse_device());


                        HouseTeSe();
                        peiZhi();
                    }

                    Log.i("Result", entity.getData().toString());

                } else if (entity.getEventType() == HousePresenter.houseZiDian_fail) {

                } else if (entity.getEventType() == UserPresenter.houseAdd_success) {
                    ByAlert.alert("房源发布成功");
                    ActivityFaBuHouse.getInstance().guanbi();// 关闭第一个页面
                    fabu_house_ok.setFocusable(true);
                    finish();
                } else if (entity.getEventType() == UserPresenter.houseAdd_fail) {
                    ByAlert.alert(entity.getMsg());
                    fabu_house_ok.setFocusable(true);
                }
            }
        }

    }
    private ArrayList<TextView> listText = new ArrayList<>();
    private ArrayList<TextView> listTextViewPeiZhi = new ArrayList<>();
    /**
     * 房源特色
     */
    @SuppressLint("NewApi")
    private void HouseTeSe() {
        StringBuffer tagIds = new StringBuffer();
        if (house_feature.size() > 0) {
            for (int i = 0; i < house_feature.size(); i++) {
                biao01.append(house_feature.get(i).getName() + ",");
                tagIds.append(house_feature.get(i).getId() + ",");
            }
            String[] str = biao01.toString().split(",");
            String[] ids = tagIds.toString().split(",");
            // 标签
            for (int i = 0; i < str.length; i++) {
                View view = LayoutInflater.from(this).inflate(
                        R.layout.item_jiaju, null);
                final TextView btn_name = (TextView) view
                        .findViewById(R.id.btn_name);

                listText.add(btn_name);
                btn_name.setBackgroundResource(R.drawable.shape_gray);
                btn_name.setText(str[i]);
                btn_name.setTag(false);
                btn_name.setTag(R.id.tagNames, "unSelect");
                btn_name.setTag(R.id.tag, ids[i]);
                arrayListTeSe.add(btn_name);
                btn_name.setTextColor(Color.parseColor("#5B5B5B"));
                btn_name.setOnClickListener(new OnClickListener() {

                    @SuppressLint("ResourceAsColor")
                    public void onClick(View v) {
                        if (!(boolean) v.getTag()) {
                            btn_name.setBackgroundResource(R.drawable.shape_blue02);
                            btn_name.setTextColor(Color.parseColor("#B1CCFC"));
                            btn_name.setTag(R.id.tagNames, "select");
                        } else {
                            btn_name.setBackgroundResource(R.drawable.shape_gray);
                            btn_name.setTextColor(Color.parseColor("#5B5B5B"));
                            btn_name.setTag(R.id.tagNames, "unSelect");
                        }
                        v.setTag(!(boolean) v.getTag());
                    }
                });
                MarginLayoutParams layoutParams = new MarginLayoutParams(
                        MarginLayoutParams.WRAP_CONTENT,
                        MarginLayoutParams.WRAP_CONTENT);
                layoutParams.setMargins(10, 10, 10, 10);
                fabu_flowLayout01.addView(view, layoutParams);
            }
            if (editBean != null) {
                for (int i = 0; i < str.length; i++) {
                    for (int j = 0; j < editBean.getTags().size(); j++) {
                        if (str[i].equals(editBean.getTags().get(j).getName())) {
                            stringTeSe.append(editBean.getTags().get(j).getId() + ",");
                            listText.get(i).setTag(true);
                            listText.get(i).setBackgroundResource(R.drawable.shape_blue02);
                            listText.get(i).setTextColor(Color.parseColor("#B1CCFC"));
                            listText.get(i).setTag(R.id.tagNames, "select");
                        }
                    }
                }
            }

        }
    }

    /**
     * 室内配置
     */
    @SuppressLint("NewApi")
    private void peiZhi() {
        StringBuffer bufferIds = new StringBuffer();
        if (house_device.size() > 0) {
            for (int i = 0; i < house_device.size(); i++) {
                biao02.append(house_device.get(i).getName() + ",");
                bufferIds.append(house_device.get(i).getId() + ",");
            }
            String[] str = biao02.toString().split(",");
            String[] ids = bufferIds.toString().split(",");
            for (int i = 0; i < str.length; i++) {
                View view = LayoutInflater.from(this).inflate(
                        R.layout.item_jiaju, null);
                final TextView btn_name = (TextView) view
                        .findViewById(R.id.btn_name);
                listTextViewPeiZhi.add(btn_name);
                btn_name.setBackgroundResource(R.drawable.shape_gray);
                btn_name.setText(str[i]);
                btn_name.setTag(false);
                btn_name.setTag(R.id.tagNames, "unSelect");
                btn_name.setTag(R.id.tag, ids[i]);
                arrayListPeiZhi.add(btn_name);
                btn_name.setTextColor(Color.parseColor("#5B5B5B"));
                btn_name.setOnClickListener(new OnClickListener() {

                    @SuppressLint({"ResourceAsColor", "NewApi"})
                    public void onClick(View v) {
                        if (!(boolean) v.getTag()) {
                            btn_name.setBackgroundResource(R.drawable.shape_blue02);
                            btn_name.setTextColor(Color.parseColor("#B1CCFC"));
                            btn_name.setTag(R.id.tagNames, "select");
                        } else {
                            btn_name.setBackgroundResource(R.drawable.shape_gray);
                            btn_name.setTextColor(Color.parseColor("#5B5B5B"));
                            btn_name.setTag(R.id.tagNames, "unSelect");
                        }
                        v.setTag(!(boolean) v.getTag());
                    }
                });

                MarginLayoutParams layoutParams = new MarginLayoutParams(
                        MarginLayoutParams.WRAP_CONTENT,
                        MarginLayoutParams.WRAP_CONTENT);
                layoutParams.setMargins(10, 10, 10, 10);
                fabu_flowLayout02.addView(view, layoutParams);
            }
            if (editBean != null) {
                for (int i = 0; i < str.length; i++) {
                    for (int j = 0; j < editBean.getHouseProps().size(); j++) {
                        if (str[i].equals(editBean.getHouseProps().get(j).getName())) {
                            stringPeiZhi.append(editBean.getHouseProps().get(j).getId() + ",");
                            listTextViewPeiZhi.get(i).setTag(true);
                            listTextViewPeiZhi.get(i).setBackgroundResource(R.drawable.shape_blue02);
                            listTextViewPeiZhi.get(i).setTextColor(Color.parseColor("#B1CCFC"));
                            listTextViewPeiZhi.get(i).setTag(R.id.tagNames, "select");
                        }
                    }
                }
            }
        }
    }


    /**
     * 支付方式
     */
    private void initOptionPicker() {//条件选择器初始化

        /**
         * 注意 ：如果是三级联动的数据(省市区等)，请参照 JsonDataActivity 类里面的写法。
         */
        pvOptionsZhiFu = new OptionsPickerView.Builder(this, new OptionsPickerView.OnOptionsSelectListener() {
            @Override
            public void onOptionsSelect(int options1, int options2, int options3, View v) {
                //返回的分别是三个级别的选中位置
                String tx = options1ItemsZhiFu.get(options1);
                fabu_fangshi.setText(tx);
                fangshi = house_pay.get(options1).getId();
            }

        })
                .setTitleText("付款方式选择")
                .setContentTextSize(16)//设置滚轮文字大小
                .setTitleSize(16)//设置标题文字大小
                .setSubCalSize(16)//设置确定按钮大小
                .setSelectOptions(0, 1)//默认选中项
                .setLineSpacingMultiplier(2.0f)//设置间距倍数,但是只能在1.2-2.0f之间
                .setDividerColor(Color.LTGRAY)//设置分割线的颜色
                .setBgColor(Color.WHITE)//滚轮背景颜色
                .setTitleBgColor(Color.WHITE)//标题背景颜色
                .setTitleColor(Color.BLACK)//标题颜色
                .setCancelColor(Color.BLACK)//取消按钮颜色
                .setSubmitColor(Color.BLACK)//确定按钮颜色
                .setTextColorCenter(Color.BLACK)//分割线之间的文字颜色
                .isCenterLabel(false) //是否只显示中间选中项的label文字，false则每项item全部都带有label。
                .setLabels("", "", "")
                .setBackgroundId(0x66000000) //设置外部遮罩颜色
                .build();
        pvOptionsZhiFu.setPicker(options1ItemsZhiFu);//二级选择器
    }
    private ArrayList<String> shi = new ArrayList<>();//室
    private ArrayList<String> ting = new ArrayList<>();//厅
    private ArrayList<String> wei = new ArrayList<>();//卫

    /**
     * 户型数据
     */
    private void getNoLinkData() {
        shi.add("1");
        shi.add("2");
        shi.add("3");
        shi.add("4");

        ting.add("0");
        ting.add("1");
        ting.add("2");
        ting.add("3");

        wei.add("0");
        wei.add("1");
        wei.add("2");
        wei.add("3");
    }
    /**
     * 户型
     */
    private void initNoLinkOptionsPicker() {// 不联动的多级选项
        pvNoLinkOptions = new OptionsPickerView.Builder(this, new OptionsPickerView.OnOptionsSelectListener() {

            @Override
            public void onOptionsSelect(int options1, int options2, int options3, View v) {
                String str =  shi.get(options1)+"室"+ting.get(options2)+"厅"+wei.get(options3)+"卫";
                fabu_huxing.setText(str);
                huxing = shi.get(options1) + ","
                        + ting.get(options2) + ","
                        + wei.get(options3) + "";
            }
        })
                .setTitleText("户型选择")
                .setContentTextSize(16)//设置滚轮文字大小
                .setTitleSize(16)//设置标题文字大小
                .setSubCalSize(16)//设置确定按钮大小
                .setSelectOptions(0, 0)//默认选中项
                .setLineSpacingMultiplier(2.0f)//设置间距倍数,但是只能在1.2-2.0f之间
                .setDividerColor(Color.LTGRAY)//设置分割线的颜色
                .setBgColor(Color.WHITE)//滚轮背景颜色
                .setTitleBgColor(Color.WHITE)//标题背景颜色
                .setTitleColor(Color.BLACK)//标题颜色
                .setCancelColor(Color.BLACK)//取消按钮颜色
                .setSubmitColor(Color.BLACK)//确定按钮颜色
                .setTextColorCenter(Color.BLACK)//分割线之间的文字颜色
                .isCenterLabel(true) //是否只显示中间选中项的label文字，false则每项item全部都带有label。
                .setLabels("室", "厅", "卫")
                .build();
        pvNoLinkOptions.setNPicker(shi, ting, wei);
    }

    private ArrayList<String> fangshis = new ArrayList<>();//出租方式数据
    /**
     * 出租方式数据
     */
    private void getNoLinkDataFangShi() {
        fangshis.add("整租");
        fangshis.add("合租-主卧");
        fangshis.add("合租-次卧");
        fangshis.add("日租");

    }
    /**
     * 出租方式
     */
    private void linkageFangShi() {// 不联动的多级选项
        pvOptionsChuZu = new OptionsPickerView.Builder(this, new OptionsPickerView.OnOptionsSelectListener() {

            @Override
            public void onOptionsSelect(int options1, int options2, int options3, View v) {
                fabu_woshi.setText(fangshis.get(options1).toString());
                type = options1 + 1;
            }
        })
                .setTitleText("出租方式选择")
                .setContentTextSize(16)//设置滚轮文字大小
                .setTitleSize(16)//设置标题文字大小
                .setSubCalSize(16)//设置确定按钮大小
                .setSelectOptions(0, 0)//默认选中项
                .setLineSpacingMultiplier(2.0f)//设置间距倍数,但是只能在1.2-2.0f之间
                .setDividerColor(Color.LTGRAY)//设置分割线的颜色
                .setBgColor(Color.WHITE)//滚轮背景颜色
                .setTitleBgColor(Color.WHITE)//标题背景颜色
                .setTitleColor(Color.BLACK)//标题颜色
                .setCancelColor(Color.BLACK)//取消按钮颜色
                .setSubmitColor(Color.BLACK)//确定按钮颜色
                .setTextColorCenter(Color.BLACK)//分割线之间的文字颜色
                .isCenterLabel(false) //是否只显示中间选中项的label文字，false则每项item全部都带有label。
                .setLabels("", "", "")
                .build();
        pvOptionsChuZu.setPicker(fangshis);
    }

    /**
     * 房源朝向
     */
    private void linkageChaoXiang() {//条件选择器初始化

        /**
         * 注意 ：如果是三级联动的数据(省市区等)，请参照 JsonDataActivity 类里面的写法。
         */
        pvOptionsChaoXiang = new OptionsPickerView.Builder(this, new OptionsPickerView.OnOptionsSelectListener() {
            @Override
            public void onOptionsSelect(int options1, int options2, int options3, View v) {
                //返回的分别是三个级别的选中位置
                String tx = options1ItemsChaoXiang.get(options1);
                fabu_chaoxiang.setText(tx);
                chaoxiang = house_orientation.get(options1)
                        .getId();
            }
        })
                .setTitleText("楼层朝向选择")
                .setContentTextSize(16)//设置滚轮文字大小
                .setTitleSize(16)//设置标题文字大小
                .setSubCalSize(16)//设置确定按钮大小
                .setSelectOptions(0, 1)//默认选中项
                .setLineSpacingMultiplier(2.0f)//设置间距倍数,但是只能在1.2-2.0f之间
                .setDividerColor(Color.LTGRAY)//设置分割线的颜色
                .setBgColor(Color.WHITE)//滚轮背景颜色
                .setTitleBgColor(Color.WHITE)//标题背景颜色
                .setTitleColor(Color.BLACK)//标题颜色
                .setCancelColor(Color.BLACK)//取消按钮颜色
                .setSubmitColor(Color.BLACK)//确定按钮颜色
                .setTextColorCenter(Color.BLACK)//分割线之间的文字颜色
                .isCenterLabel(false) //是否只显示中间选中项的label文字，false则每项item全部都带有label。
                .setLabels("", "", "")
                .setBackgroundId(0x66000000) //设置外部遮罩颜色
                .build();
        pvOptionsChaoXiang.setPicker(options1ItemsChaoXiang);//二级选择器
    }
    /**
     * 装修程度
     */
    private void linkageChengDu() {//条件选择器初始化

        /**
         * 注意 ：如果是三级联动的数据(省市区等)，请参照 JsonDataActivity 类里面的写法。
         */
        pvOptionsChengDu = new OptionsPickerView.Builder(this, new OptionsPickerView.OnOptionsSelectListener() {
            @Override
            public void onOptionsSelect(int options1, int options2, int options3, View v) {
                //返回的分别是三个级别的选中位置
                String tx = options1ItemsChengDu.get(options1);
                fabu_chengdu.setText(tx);

                chengdu = house_decoration.get(options1)
                        .getId();
            }
        })
                .setTitleText("装修程度选择")
                .setContentTextSize(16)//设置滚轮文字大小
                .setTitleSize(16)//设置标题文字大小
                .setSubCalSize(16)//设置确定按钮大小
                .setSelectOptions(0, 1)//默认选中项
                .setLineSpacingMultiplier(2.0f)//设置间距倍数,但是只能在1.2-2.0f之间
                .setDividerColor(Color.LTGRAY)//设置分割线的颜色
                .setBgColor(Color.WHITE)//滚轮背景颜色
                .setTitleBgColor(Color.WHITE)//标题背景颜色
                .setTitleColor(Color.BLACK)//标题颜色
                .setCancelColor(Color.BLACK)//取消按钮颜色
                .setSubmitColor(Color.BLACK)//确定按钮颜色
                .setTextColorCenter(Color.BLACK)//分割线之间的文字颜色
                .isCenterLabel(false) //是否只显示中间选中项的label文字，false则每项item全部都带有label。
                .setLabels("", "", "")
                .setBackgroundId(0x66000000) //设置外部遮罩颜色
                .build();
        pvOptionsChengDu.setPicker(options1ItemsChengDu);//二级选择器
    }

    private ArrayList<String> mianji = new ArrayList<>();//面积数据
    /**
     * 面积数据
     */
    private void getNoLinkDataMianJi() {
        for (int i=1;i<1000;i++){
            mianji.add(i+"");
        }
    }
    /**
     * 建筑面积
     */
    private void linkageMianJi() {// 不联动的多级选项
        pvOptionsMianJi = new OptionsPickerView.Builder(this, new OptionsPickerView.OnOptionsSelectListener() {
            @Override
            public void onOptionsSelect(int options1, int options2, int options3, View v) {
                fabu_mianji.setText(mianji.get(options1).toString());
            }
        })
                .setTitleText("住房面积选择")
                .setContentTextSize(16)//设置滚轮文字大小
                .setTitleSize(16)//设置标题文字大小
                .setSubCalSize(16)//设置确定按钮大小
                .setSelectOptions(0, 0)//默认选中项
                .setLineSpacingMultiplier(2.0f)//设置间距倍数,但是只能在1.2-2.0f之间
                .setDividerColor(Color.LTGRAY)//设置分割线的颜色
                .setBgColor(Color.WHITE)//滚轮背景颜色
                .setTitleBgColor(Color.WHITE)//标题背景颜色
                .setTitleColor(Color.BLACK)//标题颜色
                .setCancelColor(Color.BLACK)//取消按钮颜色
                .setSubmitColor(Color.BLACK)//确定按钮颜色
                .setTextColorCenter(Color.BLACK)//分割线之间的文字颜色
                .isCenterLabel(false) //是否只显示中间选中项的label文字，false则每项item全部都带有label。
                .setLabels("", "", "")
                .build();
        pvOptionsMianJi.setPicker(mianji);
    }
    private ArrayList<String> louceng = new ArrayList<>();//房源楼层选择
    /**
     * 房源楼层选择
     */
    private void getNoLinkDataLouCeng() {
        for (int i=1;i<100;i++){
            louceng.add(i+"");
        }
    }
    /**
     * 房源楼层选择
     */
    private void linkageLouCeng() {// 不联动的多级选项
        pvOptionsLouCeng = new OptionsPickerView.Builder(this, new OptionsPickerView.OnOptionsSelectListener() {
            @Override
            public void onOptionsSelect(int options1, int options2, int options3, View v) {
                fabu_louceng.setText(louceng.get(options1).toString());
            }
        })
                .setTitleText("房源楼层选择")
                .setContentTextSize(16)//设置滚轮文字大小
                .setTitleSize(16)//设置标题文字大小
                .setSubCalSize(16)//设置确定按钮大小
                .setSelectOptions(0, 0)//默认选中项
                .setLineSpacingMultiplier(2.0f)//设置间距倍数,但是只能在1.2-2.0f之间
                .setDividerColor(Color.LTGRAY)//设置分割线的颜色
                .setBgColor(Color.WHITE)//滚轮背景颜色
                .setTitleBgColor(Color.WHITE)//标题背景颜色
                .setTitleColor(Color.BLACK)//标题颜色
                .setCancelColor(Color.BLACK)//取消按钮颜色
                .setSubmitColor(Color.BLACK)//确定按钮颜色
                .setTextColorCenter(Color.BLACK)//分割线之间的文字颜色
                .isCenterLabel(false) //是否只显示中间选中项的label文字，false则每项item全部都带有label。
                .setLabels("", "", "")
                .build();
        pvOptionsLouCeng.setPicker(louceng);
    }
    private ArrayList<String> louceng_zong = new ArrayList<>();//面积数据
    /**
     * 面积数据
     */
    private void getNoLinkDataLouCengZong() {
        for (int i=1;i<100;i++){
            louceng_zong.add(i+"");
        }
    }
    /**
     * 房源楼层选择
     */
    private void linkageLouCengZong() {// 不联动的多级选项
        pvOptionsZong = new OptionsPickerView.Builder(this, new OptionsPickerView.OnOptionsSelectListener() {
            @Override
            public void onOptionsSelect(int options1, int options2, int options3, View v) {
                fabu_zong.setText(louceng_zong.get(options1).toString());
            }
        })
                .setTitleText("房源总楼层选择")
                .setContentTextSize(16)//设置滚轮文字大小
                .setTitleSize(16)//设置标题文字大小
                .setSubCalSize(16)//设置确定按钮大小
                .setSelectOptions(0, 0)//默认选中项
                .setLineSpacingMultiplier(2.0f)//设置间距倍数,但是只能在1.2-2.0f之间
                .setDividerColor(Color.LTGRAY)//设置分割线的颜色
                .setBgColor(Color.WHITE)//滚轮背景颜色
                .setTitleBgColor(Color.WHITE)//标题背景颜色
                .setTitleColor(Color.BLACK)//标题颜色
                .setCancelColor(Color.BLACK)//取消按钮颜色
                .setSubmitColor(Color.BLACK)//确定按钮颜色
                .setTextColorCenter(Color.BLACK)//分割线之间的文字颜色
                .isCenterLabel(false) //是否只显示中间选中项的label文字，false则每项item全部都带有label。
                .setLabels("", "", "")
                .build();
        pvOptionsZong.setPicker(louceng_zong);
    }
    @Override
    public void OnSuccess(ArrayList<AvatarDataBeans> resultData) {

    }

    @Override
    public void OnError(String resultData) {
        ByAlert.alert(resultData);
    }
}
